<template>
  <div class="list">
    <el-table
      stripe
      style="width: 100%;"
      :data="userList.slice((currentPage-1)*pagesize,currentPage*pagesize)"
    >
      <el-table-column label="课程编号" prop="id" min-width="100" align="center"></el-table-column>
      <el-table-column label="名称" prop="subjectname" min-width="100" align="center"></el-table-column>
      <el-table-column label="价格" prop="cost" min-width="200" align="center"></el-table-column>
      <el-table-column label="计划数" prop="number" min-width="200" align="center"></el-table-column>
      <el-table-column label="学员数" prop="studentNum" min-width="200" align="center"></el-table-column>
      <el-table-column label="创建者/时间" prop="creator" min-width="200" align="center"></el-table-column>
      <el-table-column label="课程状态" prop="subState" min-width="200" align="center"></el-table-column>
      <el-table-column label="操作" prop="handle" min-width="200" align="center">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">管</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      style="float:right;margin-top:5px;"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5,10,15]"
      :page-size="pagesize"
      layout="prev, pager,next"
      :total="userList.length"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentPage: 1,
      pagesize: 10,
      userList: [
        {
          id: 1,
          subjectname: "test",
          cost: 0,
          number: 1,
          studentNum: 0,
          creator: "管理员\n2019.2.27 14:09",
          subState: "未发布\n非连载课程"
        },
        {
          id: 1,
          subjectname: "test",
          cost: 0,
          number: 1,
          studentNum: 0,
          creator: "管理员\n2019.2.27 14:09",
          subState: "未发布\n非连载课程"
        },
        {
          id: 1,
          subjectname: "test",
          cost: 0,
          number: 1,
          studentNum: 0,
          creator: "管理员\n2019.2.27 14:09",
          subState: "未发布\n非连载课程"
        },
        {
          id: 1,
          subjectname: "test",
          cost: 0,
          number: 1,
          studentNum: 0,
          creator: "管理员\n2019.2.27 14:09",
          subState: "未发布\n非连载课程"
        },
        {
          id: 1,
          subjectname: "test",
          cost: 0,
          number: 1,
          studentNum: 0,
          creator: "管理员\n2019.2.27 14:09",
          subState: "未发布\n非连载课程"
        },
        {
          id: 1,
          subjectname: "test",
          cost: 0,
          number: 1,
          studentNum: 0,
          creator: "管理员 \n 2019.2.27 14:09",
          subState: "未发布\n非连载课程"
        },
        {
          id: 1,
          subjectname: "test",
          cost: 0,
          number: 1,
          studentNum: 0,
          creator: "管理员\n2019.2.27 14:09",
          subState: "未发布\n非连载课程"
        },
      ]
    };
  },
  methods: {
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function(size) {
      this.pagesize = size;
      console.log(this.pagesize); //每页下拉显示数据
    },
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage;
      console.log(this.currentPage); //点击第几页
    }
  }
};
</script>

<style>
.el-table .cell {
  white-space: pre-line；;
}
.list {
  margin-top: 30px;
}
</style>
